﻿using Microsoft.Extensions.ObjectPool;
using WAU.Library.ObjectPool;
using RabbitMQChannel = RabbitMQ.Client.IModel;
using RabbitMQConnection = RabbitMQ.Client.IConnection;

namespace WAU.Library.RabbitMQ
{
    /// <summary>
    /// Scope 生命周期的 RabbitMQChannel 包装类对象
    /// </summary>
    public class ScopedRabbitMQModelLease : IDisposable
    {
        /// <summary>
        /// RabbitMQChannel 包装类对象
        /// </summary>
        private RabbitMQModelLease _lease;

        /// <summary>
        /// ctor
        /// </summary>
        /// <param name="pool"></param>
        public ScopedRabbitMQModelLease(SimpleRudeObjectPool<RabbitMQChannel> pool)
        {
            _lease = new RabbitMQModelLease(pool);
        }

        /// <summary>
        /// Channel
        /// </summary>
        public RabbitMQChannel Channel => _lease.Channel;

        /// <summary>
        /// Dispose
        /// </summary>
        public void Dispose()
        {
            _lease.Release();
        }
    }
}
